package com.algorithm.tencent;

/**
 * 反转整数
 */
public class ReverseInteger {
    public static void main(String[] args) {
        System.out.println(reverse(1534236469));
    }

    public static int reverse(int x) {
        long res = 0;
        while (x / 10 != 0) {
            res = res * 10 + x % 10;
            x = x / 10;
        }
        res = res * 10 + x;
        if (res > Integer.MAX_VALUE | res<Integer.MIN_VALUE){
            return 0;
        }else {
            return (int) res;
        }
    }
}
